<?php

namespace App\Enums\OpenShop;


class AreaBaseEnum
{
    const DONGBEI  = '东北地区';
    const HUADONG  = '华东地区';
    const HUABEI   = '华北地区';
    const HUAZHONG = '华中地区';
    const HUANAN   = '华南地区';
    const XINAN    = '西南地区';
    const XIBEI    = '西北地区';

    const AREA = [
        self::DONGBEI => [
            '黑龙江省',
            '吉林省',
            '辽宁省',
        ],
        self::HUADONG => [
            '上海市',
            '江苏省',
            '浙江省',
            '安徽省',
            '福建省',
            '江西省',
            '山东省',
            '台湾省',
        ],
        self::HUABEI => [
            '北京市',
            '天津市',
            '山西省',
            '河北省',
            '内蒙古自治区',
        ],
        self::HUAZHONG => [
            '河南省',
            '湖北省',
            '湖南省',
        ],
        self::HUANAN => [
            '广东省',
            '广西壮族自治区',
            '海南省',
            '香港特别行政区',
            '澳门特别行政区',
        ],
        self::XINAN => [
            '四川省',
            '贵州省',
            '云南省',
            '重庆市',
            '西藏自治区',
        ],
        self::XIBEI => [
            '陕西省',
            '甘肃省',
            '青海省',
            '宁夏回族自治区',
            '新疆维吾尔自治区',
        ],
    ];

    const AREA_CODE = [
        self::DONGBEI => [
            '230000',
            '220000',
            '210000',
            '150400',
            '150500',
            '150700',
            '152200',
            '152500',
            '130300',
            '130800',
        ],
        self::HUADONG => [
            '310000',
            '320000',
            '330000',
            '340000',
            '350000',
            '360000',
            '370000',
            '710000',
        ],
        self::HUABEI => [
            '110000',
            '120000',
            '140000',
            '130000',
            '150000',
            '150600',
            '150200',
            '150900',
            '150100',
        ],
        self::HUAZHONG => [
            '410000',
            '420000',
            '430000',
        ],
        self::HUANAN => [
            '440000',
            '450000',
            '460000',
            '810000',
            '820000',
        ],
        self::XINAN => [
            '510000',
            '520000',
            '530000',
            '500000',
            '540000',
        ],
        self::XIBEI => [
            '610000',
            '620000',
            '630000',
            '640000',
            '650000',
            '150300',
            '150800',
            '152900',
        ],
    ];

    /*
     * 根据省份转区域
     */
    public static function provinceToRegion($province): string
    {
        if (!mb_strlen($province)) {
            return '未知地区';
        }
        foreach (self::AREA as $k => $item) {
            if (in_array($province, $item)) {
                return $k;
            }
        }
        return '未知地区';
    }

    /*
     * 根据code转区域
     */
    public static function provinceCodeToRegion($provinceCode, $city = ''): string
    {
        if (!mb_strlen($provinceCode)) {
            return '未知地区';
        }
        foreach (self::AREA_CODE as $k => $item) {
            if (in_array($provinceCode, $item)) {
                if ($provinceCode == 150000 || $provinceCode == 130000) {
                    foreach (self::AREA_CODE as $key => $value) {
                        if (in_array($city, $value)) {
                            return $key;
                        }
                    }
                }
                return $k;
            }
        }
        return '未知地区';
    }
}
